package com.ymatou.query.trading.api.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Map;
import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.query.trading.api.parameter.GetOrderSummaryInfoBean;
import com.ymatou.query.trading.api.service.GetOrderSummaryInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.utils.constant.ECode;

/**
 * 获取订单物流信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetOrderSummaryInfo {

	private static GetOrderSummaryInfoBean gosibean;
	private static GetOrderSummaryInfoCall gosicall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取订单物流信息");
	}

	@Before
	public void caseUp() {

		gosibean = new GetOrderSummaryInfoBean();
		gosicall = new GetOrderSummaryInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(gosicall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderSummaryInfo_001() {
		Logger.start(true,"获取订单物流信息成功");
		try {
			// 创建订单
			Map map = new OrderCallService().appSaveOrder();		
			int orderId = (Integer) map.get("orderId");
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");
			DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
			BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
			// 买家付款
			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 卖家发起补款
			int price = 1+new Random().nextInt(50);
			BigDecimal payAmount = new BigDecimal(df.format(price));
			String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
			// 买家补款
			new OrderCallService().orderPostPayRequest(userId, payAmount, orderId);
			// 商家发货
			String deliverSummary=new OrderCallService().dispatched(orderId, sellerId);
			// 请求参数
			gosibean.setOrderId(orderId);
			// 发送请求
			gosicall.setData(gosibean);
			gosicall.callService();
			Logger.comment("gosicall send:" + gosicall.getEntityString());
			Logger.comment("gosicall response:" + gosicall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, gosicall.getCode(), "验证Code");
			// Logger.verifyEquals(ErrorCode.SUCCESSMSG, gosicall.getMsg(),
			// "验证Msg");
			Logger.verifyEquals(deliverSummary, gosicall.getOrderSummaryInfo(), "验证物流单号");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}